package com.multitrack.map.util;

import java.util.Iterator;
import android.location.Location;
import com.google.android.maps.GeoPoint;
import com.multitrack.datatype.GPS;
import com.multitrack.datatype.GPSList;
import com.multitrack.map.datatype.GeoPoints;

public class Convert extends GeoPoint {

	public Convert(int lat, int lon) {
		super(lat, lon);
	}

	final static double convertInt = 1E6;

	public static GeoPoint toGeoPoint(Location loc) {

		return new GeoPoint((int) (loc.getLatitude() * convertInt),
				(int) (loc.getLongitude() * convertInt));
	}

	public static GeoPoint toGeoPoint(double lat, double lon) {

		return new GeoPoint((int) (lat * convertInt), (int) (lon * convertInt));
	}

	public static GeoPoint toGeoPoint(GPS gps) {
		return new GeoPoint((int) (gps.getLat() * convertInt),
				(int) (gps.getLon() * convertInt));
	}

	public static GPS toGPS(GeoPoint geopoint) {
		return new GPS(geopoint.getLatitudeE6() / convertInt,
				geopoint.getLongitudeE6() / convertInt);
	}

	public static GeoPoints toGeoPoint(GPSList gpsList) {

		GeoPoints geoPoints = new GeoPoints();

		Iterator<GPS> it = gpsList.iterator();

		while (it.hasNext()) {

			geoPoints.add(Convert.toGeoPoint(it.next()));
		}

		return geoPoints;

	}
}
